<template>
  <div>
    <el-dialog :title="dialogDict.title" :visible.sync="dialogDict.show" width="30%" @open="openFun">
      <el-form ref="form" :model="formData" label-width="80px" :rules="rules">
          <el-form-item label="类型" prop="type">
            <el-input placeholder="请输入类型" v-model="formData.type" v-if="formData.operation == 2" disabled></el-input>
            <el-input placeholder="请输入类型" v-model="formData.type" v-if="formData.operation != 2"></el-input>
          </el-form-item>
          <el-form-item label="描述" prop="description" >
            <el-input placeholder="请输入描述" v-model="formData.description"></el-input>
          </el-form-item>
          <el-form-item label="字典类型" prop="system">
            <el-select v-model="formData.system" placeholder="请选择字典类型" class="filter-item">
              <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="备注信息" prop="remarks">
            <el-input placeholder="请输入备注信息" v-model="formData.remarks"></el-input>
          </el-form-item>
          <el-form-item label="创建时间" prop="createTime" v-if="formData.operation == 2">
            <el-input disabled v-model="formData.createTime" suffix-icon="el-icon-date">
              <template slot-scope="scope">
                {{ scope.createTime | formatDateTime }}
              </template>
            </el-input>
          </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="resetForm('form')">取 消</el-button>
        <el-button type="primary" @click="handleSubmit('form')">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  props: {
    dialogDict: Object,
    formData: Object
  },
  data() {
    return {
      systemKey: "",
      options: [
        {
          value: "1",
          label: "系统类",
        },
        {
          value: "0",
          label: "业务类",
        },
      ],
      rules: {
        type: [{ required: true, message: '请输入类型', trigger: 'blur' }],
        description: [{ required: true, message: '请输入描述', trigger: 'blur' }],
        system: [{ required: true, message: '请选择字典类型', trigger: 'change' }],
      }
    }
  },
  methods: {
    // 弹窗打开触发的方法
    openFun() {
      
    },

    // 点击确定按钮触发
    handleSubmit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          if (this.dialogDict.option == 'add') {
            this.$emit("handleSubmit")
          } else {
            this.$emit("handleSubmitEdit")
          }
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    // 点击取消按钮触发
    resetForm(formName) {
      this.dialogDict.show = false
      this.$refs[formName].resetFields();
    }
  },
}
</script>

<style lang="scss" scoped>
</style>